﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.RBACs;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace RBAC.Write.API.Applications.PermissionsFiles
{
    public class PermissisonListHander : IRequestHandler<PermissisonListCommand, ResultsDTO<Permissions>>
    {
        private readonly IBateRepository<Permissions> per;

        public PermissisonListHander(IBateRepository<Permissions> per)
        {
            this.per = per;
        }

        public async Task<ResultsDTO<Permissions>> Handle(PermissisonListCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Permissions pers=new Permissions();
                ResultsDTO<Permissions> res = new ResultsDTO<Permissions>();
                string sql = "select * from permissions";
                DapperHelper dapperHelper = new DapperHelper();
                res.Data = per.GetAll(sql,pers, dapperHelper.RBACRead).ToList();
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
